using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SkeletonGroundState : EnemyState
{
    protected Enemy_Skeleton enemy;
    private Transform player;

    // 构造函数，初始化敌人和状态机
    public SkeletonGroundState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName, Enemy_Skeleton _enemy) : base(_enemy, _stateMachine, _animBoolName)
    {
        this.enemy = _enemy;
    }

    // 进入状态时调用
    public override void Enter()
    {
        base.Enter();
        player = PlayerManager.instance.player.transform; // 通过玩家管理器获取玩家
    }

    // 退出状态时调用
    public override void Exit()
    {
        base.Exit();
    }

    // 每帧更新时调用
    public override void Update()
    {
        base.Update();
        // 发现玩家或距离小于2进入战斗状态
        if (enemy.IsPlayerDetected() || Vector2.Distance(player.position, enemy.transform.position) < 2)
        {
            stateMachine.ChangeState(enemy.battleState);
        }
    }
}